home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / namcos2.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  44KB  |  1,248 lines

  1. /* video hardware for Namco System II */
  2.  
  3. #include "driver.h"
  4. #include "vidhrdw/generic.h"
  5. #include "machine/namcos2.h"
  6.  
  7. #define ROTATE_TILE_WIDTH   256
  8. #define ROTATE_TILE_HEIGHT  256
  9. #define ROTATE_PIXEL_WIDTH  (ROTATE_TILE_WIDTH*8)
  10. #define ROTATE_PIXEL_HEIGHT (ROTATE_TILE_HEIGHT*8)
  11. #define ROTATE_MASK_WIDTH   (ROTATE_PIXEL_WIDTH-1)
  12. #define ROTATE_MASK_HEIGHT  (ROTATE_PIXEL_HEIGHT-1)
  13. #define get_gfx_pointer(gfxelement,c,line) (gfxelement->gfxdata + (c*gfxelement->height+line) * gfxelement->line_modulo)
  14.  
  15. #ifdef NAMCOS2_DEBUG_MODE
  16. static int namcos2_used_colour_count=0;
  17. static int namcos2_used_colour_cached=0;
  18. static int namcos2_max_used_colour_count=0;
  19. static int namcos2_max_used_colour_cached=0;
  20. /* extern int palette_max_ran_out; */
  21. /* extern int palette_ran_out; */
  22. #endif
  23.  
  24. struct tilemap *namcos2_tilemap0=NULL;
  25. struct tilemap *namcos2_tilemap1=NULL;
  26. struct tilemap *namcos2_tilemap2=NULL;
  27. struct tilemap *namcos2_tilemap3=NULL;
  28. struct tilemap *namcos2_tilemap4=NULL;
  29. struct tilemap *namcos2_tilemap5=NULL;
  30.  
  31. int namcos2_tilemap0_flip=0;
  32. int namcos2_tilemap1_flip=0;
  33. int namcos2_tilemap2_flip=0;
  34. int namcos2_tilemap3_flip=0;
  35. int namcos2_tilemap4_flip=0;
  36. int namcos2_tilemap5_flip=0;
  37.  
  38. static void namcos2_tilemap0_get_info( int tile_index ){
  39.     int tile,colour;
  40.     tile=READ_WORD(&videoram[0x0000+(tile_index<<1)]);
  41.     /* The tile mask DOESNT use the mangled tile number */
  42.     tile_info.mask_data = memory_region(REGION_GFX4)+(0x08*tile);
  43.     /* The order of bits needs to be corrected to index the right tile  14 15 11 12 13 */
  44.     tile=(tile&0x07ff)|((tile&0xc000)>>3)|((tile&0x3800)<<2);
  45.     colour=namcos2_68k_vram_ctrl_r(0x30)&0x0007;
  46.  
  47.     SET_TILE_INFO(GFX_CHR,tile,colour)
  48. }
  49.  
  50. static void namcos2_tilemap1_get_info( int tile_index ){
  51.     int tile,colour;
  52.     tile=READ_WORD(&videoram[0x2000+(tile_index<<1)]);
  53.     /* The tile mask DOESNT use the mangled tile number */
  54.     tile_info.mask_data = memory_region(REGION_GFX4)+0x08*tile;
  55.     /* The order of bits needs to be corrected to index the right tile  14 15 11 12 13 */
  56.     tile=(tile&0x07ff)|((tile&0xc000)>>3)|((tile&0x3800)<<2);
  57.     colour=namcos2_68k_vram_ctrl_r(0x32)&0x0007;
  58.     SET_TILE_INFO(GFX_CHR,tile,colour)
  59. }
  60.  
  61. static void namcos2_tilemap2_get_info( int tile_index ){
  62.     int tile,colour;
  63.     tile=READ_WORD(&videoram[0x4000+(tile_index<<1)]);
  64.     /* The tile mask DOESNT use the mangled tile number */
  65.     tile_info.mask_data = memory_region(REGION_GFX4)+(0x08*tile);
  66.     /* The order of bits needs to be corrected to index the right tile  14 15 11 12 13 */
  67.     tile=(tile&0x07ff)|((tile&0xc000)>>3)|((tile&0x3800)<<2);
  68.     colour=namcos2_68k_vram_ctrl_r(0x34)&0x0007;
  69.     SET_TILE_INFO(GFX_CHR,tile,colour)
  70. }
  71.  
  72. static void namcos2_tilemap3_get_info( int tile_index ){
  73.     int tile,colour;
  74.     tile=READ_WORD(&videoram[0x6000+(tile_index<<1)]);
  75.     /* The tile mask DOESNT use the mangled tile number */
  76.     tile_info.mask_data = memory_region(REGION_GFX4)+(0x08*tile);
  77.     /* The order of bits needs to be corrected to index the right tile  14 15 11 12 13 */
  78.     tile=(tile&0x07ff)|((tile&0xc000)>>3)|((tile&0x3800)<<2);
  79.     colour=namcos2_68k_vram_ctrl_r(0x36)&0x0007;
  80.     SET_TILE_INFO(GFX_CHR,tile,colour)
  81. }
  82.  
  83. static void namcos2_tilemap4_get_info( int tile_index ){
  84.     int tile,colour;
  85.     tile=READ_WORD(&videoram[0x8010+(tile_index<<1)]);
  86.     /* The tile mask DOESNT use the mangled tile number */
  87.     tile_info.mask_data = memory_region(REGION_GFX4)+(0x08*tile);
  88.     /* The order of bits needs to be corrected to index the right tile  14 15 11 12 13 */
  89.     tile=(tile&0x07ff)|((tile&0xc000)>>3)|((tile&0x3800)<<2);
  90.     colour=namcos2_68k_vram_ctrl_r(0x38)&0x0007;
  91.     SET_TILE_INFO(GFX_CHR,tile,colour)
  92. }
  93.  
  94. static void namcos2_tilemap5_get_info( int tile_index ){
  95.     int tile,colour;
  96.     tile=READ_WORD(&videoram[0x8810+(tile_index<<1)]);
  97.     /* The tile mask DOESNT use the mangled tile number */
  98.     tile_info.mask_data = memory_region(REGION_GFX4)+(0x08*tile);
  99.     /* The order of bits needs to be corrected to index the right tile  14 15 11 12 13 */
  100.     tile=(tile&0x07ff)|((tile&0xc000)>>3)|((tile&0x3800)<<2);
  101.     colour=namcos2_68k_vram_ctrl_r(0x3a)&0x0007;
  102.     SET_TILE_INFO(GFX_CHR,tile,colour)
  103. }
  104.  
  105. int namcos2_calc_used_pens(int gfx_zone,int tile,char *penused){
  106.     unsigned char* gfxdata=NULL;
  107.     int pix_y=0,pix_x=0;
  108.     int height=0,width=0;
  109.     int pencount=0;
  110.  
  111.     height=Machine->gfx[gfx_zone]->height;
  112.     width=Machine->gfx[gfx_zone]->width;
  113.  
  114.     for(pix_y=0;pix_y<height;pix_y++){
  115.         gfxdata=get_gfx_pointer(Machine->gfx[gfx_zone],tile,pix_y);
  116.  
  117.         for(pix_x=0;pix_x<width;pix_x++){
  118.             penused[(gfxdata[pix_x])>>3]|=1<<(gfxdata[pix_x]&0x07);
  119.         }
  120.     }
  121. //    for(pix_y=0;pix_y<256;pix_y++) if((penused[pix_y>>3])&(1<<(pix_y&0x07))) pencount++;
  122.     return pencount;
  123. }
  124.  
  125. void namcos2_mark_used_ROZ_colours(void){
  126.     int tile,coloop,colour_code;
  127.     /* Array to mark when a particular tile has had its colours marked  */
  128.     /* so we dont scan it again if its marked in here                   */
  129.     char pen_array[256/8];
  130.     char tile_is_visible_array[0x10000/8];
  131.  
  132.     /* Rather than scan the whole 256x256 tile array marking used colours */
  133.     /* what we'll do is do a normal rotate of the image and instead of    */
  134.     /* copying any data we'll just use the pixel position to mark the     */
  135.     /* tile as being used and more importantly visible. Then scan the     */
  136.     /* array of visible used tiles and mark the pens of any used tile     */
  137.  
  138.     /* Blat the used array */
  139.     memset(tile_is_visible_array,0,0x10000/8);
  140.  
  141.     /* This is a clone of the drawROZ core code */
  142.     {
  143.         int dest_x,dest_x_delta,dest_x_start,dest_x_end,tmp_x;
  144.         int dest_y,dest_y_delta,dest_y_start,dest_y_end,tmp_y;
  145.         int right_dx,right_dy,down_dx,down_dy,start_x,start_y;
  146.  
  147.         /* These need to be sign extended for arithmetic useage */
  148.         right_dx = namcos2_68k_roz_ctrl_r(0x06);
  149.         right_dy = namcos2_68k_roz_ctrl_r(0x02);
  150.         down_dx  = namcos2_68k_roz_ctrl_r(0x04);
  151.         down_dy  = namcos2_68k_roz_ctrl_r(0x00);
  152.         start_y  = namcos2_68k_roz_ctrl_r(0x0a);
  153.         start_x  = namcos2_68k_roz_ctrl_r(0x08);
  154.  
  155.         /* Sign extend the deltas */
  156.         if(right_dx&0x8000) right_dx|=0xffff0000;
  157.         if(right_dy&0x8000) right_dy|=0xffff0000;
  158.         if(down_dx &0x8000) down_dx |=0xffff0000;
  159.         if(down_dy &0x8000) down_dy |=0xffff0000;
  160.  
  161.         /* Correct to 16 bit fixed point from 8/12 bit */
  162.         right_dx <<=8;
  163.         right_dy <<=8;
  164.         down_dx  <<=8;
  165.         down_dy  <<=8;
  166.         start_x  <<=12;
  167.         start_y  <<=12;
  168.  
  169.         /* Correction factor is needed for the screen offset */
  170.         start_x+=38*right_dx;
  171.         start_y+=38*right_dy;
  172.  
  173.         if(Machine->orientation & ORIENTATION_SWAP_XY)
  174.         {
  175.             int tmp;
  176.             tmp=right_dx; right_dx=down_dx; down_dx=tmp;
  177.             tmp=right_dy; right_dy=down_dy; down_dy=tmp;
  178.         }
  179.  
  180.         dest_y_delta=(Machine->orientation & ORIENTATION_FLIP_Y)?-1:1;
  181.         dest_y_start=(Machine->orientation & ORIENTATION_FLIP_Y)?Machine->scrbitmap->height-1:0;
  182.         dest_y_end  =(Machine->orientation & ORIENTATION_FLIP_Y)?-1:Machine->scrbitmap->height;
  183.  
  184.         dest_x_delta=(Machine->orientation & ORIENTATION_FLIP_X)?-1:1;
  185.         dest_x_start=(Machine->orientation & ORIENTATION_FLIP_X)?Machine->scrbitmap->width-1:0;
  186.         dest_x_end  =(Machine->orientation & ORIENTATION_FLIP_X)?-1:Machine->scrbitmap->width;
  187.  
  188.         for( dest_y=dest_y_start; dest_y!=dest_y_end; dest_y+=dest_y_delta )
  189.         {
  190.             tmp_x = start_x;
  191.             tmp_y = start_y;
  192.  
  193.             for( dest_x=dest_x_start; dest_x!=dest_x_end; dest_x+=dest_x_delta )
  194.             {
  195.                 int xind=(tmp_x>>16)&ROTATE_MASK_HEIGHT;
  196.                 int yind=(tmp_y>>16)&ROTATE_MASK_WIDTH;
  197.  
  198.                 /* First reduce the x/y to tile & x/y subpixels */
  199.                 int ram_offset=(((yind>>3)<<8)+(xind>>3))<<1;
  200.                 /* Now fetch the tile number from ROZ RAM */
  201.                 tile=READ_WORD(&namcos2_68k_roz_ram[ram_offset]);
  202.                 /* Mark the tile as being visible */
  203.                 tile_is_visible_array[tile>>3]|=1<<(tile&0x07);
  204.                 /* Move on a little */
  205.                 tmp_x += right_dx;
  206.                 tmp_y += right_dy;
  207.             }
  208.             start_x += down_dx;
  209.             start_y += down_dy;
  210.         }
  211.     }
  212.     /* Set the correct colour code */
  213.     colour_code=(namcos2_68k_sprite_bank_r(0)>>8)&0x000f;
  214.     colour_code*=256;
  215.  
  216.     /* Now we have an array with all visible tiles marked, scan it and mark the used colours */
  217.     for(tile=0;tile<0x10000;tile++)
  218.     {
  219.         /* Check if tile has been done before */
  220.         if( tile_is_visible_array[tile>>3]&(1<<(tile&0x07)) )
  221.         {
  222.             /* Clear the temporary pen usage array */
  223.             memset(pen_array,0,256/8);
  224.             /* Generate pen usage array for this tile on the fly */
  225.             namcos2_calc_used_pens(GFX_ROZ,tile,pen_array);
  226.  
  227.             /* Process tile used colours */
  228.             for(coloop=0;coloop<256;coloop++)
  229.             {
  230.                 /* Is this pen marked by the tile as being used ? */
  231.                 if( pen_array[coloop>>3]&(1<<(coloop&0x07)) )
  232.                 {
  233.                     /* Yes so mark it for the palette manager */
  234.                     palette_used_colors[colour_code+coloop] |= PALETTE_COLOR_VISIBLE;
  235.                 }
  236.             }
  237.         }
  238.     }
  239. }
  240.  
  241. void namcos2_mark_used_sprite_colours(void){
  242.     int offset,loop,coloop;
  243.     /* Array to mark when a particular tile has had its colours marked  */
  244.     /* so we dont scan it again if its marked in here                   */
  245.     static char done_array[0x1000/8];
  246.     static char pen_array[256/8];
  247.  
  248.     /* Blat the used array */
  249.     memset(done_array,0,0x1000/8);
  250.  
  251.     /* Mark off all of the colour codes used by the sprites */
  252.     offset=(namcos2_68k_sprite_bank_r(0)&0x000f)*(128*8);
  253.     for(loop=0;loop<128;loop++)
  254.     {
  255.         int sizey=(READ_WORD(&namcos2_sprite_ram[offset+(loop*8)+0])>>10)&0x3f;
  256.  
  257.         /* Sprites are only active if they have a size>0 */
  258.         if(sizey)
  259.         {
  260.             int offset2=READ_WORD(&namcos2_sprite_ram[offset+(loop*8)+2]);
  261.             int offset6=READ_WORD(&namcos2_sprite_ram[offset+(loop*8)+6]);
  262.             int sprn,sprn_done,spr_region,colour_code;
  263.  
  264.             /* Calulate spr number, region, colour code & the done sprite number */
  265.             sprn=(offset2>>2)&0x7ff;
  266.             sprn_done=sprn;
  267.             sprn_done+=(offset2&0x2000)?0x800:0;
  268.             spr_region=(offset2&0x2000)?GFX_OBJ2:GFX_OBJ1;
  269.             colour_code=256*((offset6>>4)&0x000f);
  270.  
  271.             if( (done_array[sprn_done>>3]&(1<<(sprn_done&0x07)))==0 )
  272.             {
  273.                 /* Clear the temporary pen usage array */
  274.                 memset(pen_array,0,256/8);
  275.                 /* Generate pen usage array for this tile on the fly */
  276.                 namcos2_calc_used_pens(spr_region,sprn,pen_array);
  277.  
  278.                 /* Process tile used colours */
  279.                 for(coloop=0;coloop<256;coloop++)
  280.                 {
  281.                     /* Is this pen marked by the tile as being used ? */
  282.                     if( pen_array[coloop>>3]&(1<<(coloop&0x07)) )
  283.                     {
  284.                         /* Yes so mark it for the palette manager */
  285.                         palette_used_colors[colour_code+coloop] |= PALETTE_COLOR_VISIBLE;
  286.                     }
  287.                 }
  288.  
  289.                 /* Mark the tile as having been done */
  290.                 done_array[sprn_done>>3]|=1<<(sprn_done&0x07);
  291.             }
  292.         }
  293.     }
  294. }
  295.  
  296. int namcos2_vh_start(void){
  297. #ifdef NAMCOS2_DEBUG_MODE
  298.     namcos2_used_colour_count=0;
  299.     namcos2_used_colour_cached=0;
  300.     namcos2_max_used_colour_count=0;
  301.     namcos2_max_used_colour_cached=0;
  302. /*    palette_max_ran_out=0;*/
  303. /*    palette_ran_out=0;*/
  304. #endif
  305.     namcos2_tilemap0 = tilemap_create( namcos2_tilemap0_get_info,tilemap_scan_rows,TILEMAP_BITMASK,8,8,64,64 );
  306.     namcos2_tilemap1 = tilemap_create( namcos2_tilemap1_get_info,tilemap_scan_rows,TILEMAP_BITMASK,8,8,64,64 );
  307.     namcos2_tilemap2 = tilemap_create( namcos2_tilemap2_get_info,tilemap_scan_rows,TILEMAP_BITMASK,8,8,64,64 );
  308.     namcos2_tilemap3 = tilemap_create( namcos2_tilemap3_get_info,tilemap_scan_rows,TILEMAP_BITMASK,8,8,64,64 );
  309.     namcos2_tilemap4 = tilemap_create( namcos2_tilemap4_get_info,tilemap_scan_rows,TILEMAP_BITMASK,8,8,36,28 );
  310.     namcos2_tilemap5 = tilemap_create( namcos2_tilemap5_get_info,tilemap_scan_rows,TILEMAP_BITMASK,8,8,36,28 );
  311.  
  312.     if( !(namcos2_tilemap0 && namcos2_tilemap1 && namcos2_tilemap2 &&
  313.           namcos2_tilemap3 && namcos2_tilemap4 && namcos2_tilemap5) )
  314.     return 1; /* insufficient memory */
  315.  
  316.     /* Setup fixed planes */
  317.     tilemap_set_scrollx( namcos2_tilemap4, 0, 0 );
  318.     tilemap_set_scrolly( namcos2_tilemap4, 0, 0 );
  319.     tilemap_set_scrollx( namcos2_tilemap5, 0, 0 );
  320.     tilemap_set_scrolly( namcos2_tilemap5, 0, 0 );
  321.  
  322.     namcos2_tilemap0_flip=0;
  323.     namcos2_tilemap1_flip=0;
  324.     namcos2_tilemap2_flip=0;
  325.     namcos2_tilemap3_flip=0;
  326.     namcos2_tilemap4_flip=0;
  327.     namcos2_tilemap5_flip=0;
  328.  
  329.     tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
  330.  
  331.     /* Rotate/Flip the mask ROM */
  332.  
  333. #ifndef PREROTATE_GFX
  334.  
  335. //
  336. //  TILEMAP MANAGER SEEMS TO BE ABLE TO COPE OK WITH X/Y FLIPS BUT NOT SWAPXY
  337. //
  338. //    if (Machine->orientation & ORIENTATION_FLIP_Y)
  339. //    {
  340. //        int loopY,tilenum;
  341. //        unsigned char tilecache[8],*tiledata;
  342. //        for(tilenum=0;tilenum<0x10000;tilenum++)
  343. //        {
  344. //            tiledata=memory_region(REGION_GFX4)+(tilenum*0x08);
  345. //            /* Cache tile data */
  346. //            for(loopY=0;loopY<8;loopY++) tilecache[loopY]=tiledata[loopY];
  347. //            /* Flip in Y - write back in reverse */
  348. //            for(loopY=0;loopY<8;loopY++) tiledata[loopY]=tilecache[7-loopY];
  349. //        }
  350. //    }
  351.  
  352. //    if (Machine->orientation & ORIENTATION_FLIP_X)
  353. //    {
  354. //        int loopX,loopY,tilenum;
  355. //        unsigned char tilecache[8],*tiledata;
  356. //        for(tilenum=0;tilenum<0x10000;tilenum++)
  357. //        {
  358. //            tiledata=memory_region(REGION_GFX4)+(tilenum*0x08);
  359. //            /* Cache tile data */
  360. //            for(loopY=0;loopY<8;loopY++) tilecache[loopY]=tiledata[loopY];
  361. //            /* Wipe source data */
  362. //            for(loopY=0;loopY<8;loopY++) tiledata[loopY]=0;
  363. //            /* Flip in X - do bit reversal */
  364. //            for(loopY=0;loopY<8;loopY++)
  365. //            {
  366. //                for(loopX=0;loopX<8;loopX++)
  367. //                {
  368. //                    tiledata[loopY]|=(tilecache[loopY]&(1<<loopX))?(0x80>>loopX):0x00;
  369. //                }
  370. //            }
  371. //        }
  372. //    }
  373.  
  374.     if (Machine->orientation & ORIENTATION_SWAP_XY)
  375.     {
  376.         int loopX,loopY,tilenum;
  377.         unsigned char tilecache[8],*tiledata;
  378.  
  379.         for(tilenum=0;tilenum<0x10000;tilenum++)
  380.         {
  381.             tiledata=memory_region(REGION_GFX4)+(tilenum*0x08);
  382.             /* Cache tile data */
  383.             for(loopY=0;loopY<8;loopY++) tilecache[loopY]=tiledata[loopY];
  384.             /* Wipe source data */
  385.             for(loopY=0;loopY<8;loopY++) tiledata[loopY]=0;
  386.             /* Swap X/Y data */
  387.             for(loopY=0;loopY<8;loopY++)
  388.             {
  389.                 for(loopX=0;loopX<8;loopX++)
  390.                 {
  391.                     tiledata[loopX]|=(tilecache[loopY]&(0x01<<loopX))?(1<<loopY):0x00;
  392.                 }
  393.             }
  394.         }
  395.  
  396.         /* For some reason the tilemap mgr NEEDS these additional steps */
  397.         /* I've no idea why but it seems to work                        */
  398.  
  399.         for(tilenum=0;tilenum<0x10000;tilenum++)
  400.         {
  401.             tiledata=memory_region(REGION_GFX4)+(tilenum*0x08);
  402.             /* Cache tile data */
  403.             for(loopY=0;loopY<8;loopY++) tilecache[loopY]=tiledata[loopY];
  404.             /* Flip in Y - write back in reverse */
  405.             for(loopY=0;loopY<8;loopY++) tiledata[loopY]=tilecache[7-loopY];
  406.         }
  407.  
  408.         for(tilenum=0;tilenum<0x10000;tilenum++)
  409.         {
  410.             tiledata=memory_region(REGION_GFX4)+(tilenum*0x08);
  411.             /* Cache tile data */
  412.             for(loopY=0;loopY<8;loopY++) tilecache[loopY]=tiledata[loopY];
  413.             /* Wipe source data */
  414.             for(loopY=0;loopY<8;loopY++) tiledata[loopY]=0;
  415.             /* Flip in X - do bit reversal */
  416.             for(loopY=0;loopY<8;loopY++)
  417.             {
  418.                 for(loopX=0;loopX<8;loopX++)
  419.                 {
  420.                     tiledata[loopY]|=(tilecache[loopY]&(1<<loopX))?(0x80>>loopX):0x00;
  421.                 }
  422.             }
  423.         }
  424.     }
  425.  
  426. #endif
  427.  
  428.     return 0;
  429. }
  430.  
  431.  
  432. void namcos2_vh_stop(void)
  433. {
  434.     tmpbitmap = 0;
  435. }
  436.  
  437.  
  438. void namcos2_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  439. {
  440.     int i;
  441.     /* Zap the palette to Zero */
  442.  
  443.     for( i = 0; i < Machine->drv->total_colors; i++ )
  444.     {
  445.         palette[i*3+0] = 0;
  446.         palette[i*3+1] = 0;
  447.         palette[i*3+2] = 0;
  448.     }
  449. }
  450.  
  451.  
  452. #ifdef NAMCOS2_DEBUG_MODE
  453.  
  454. #define TITLE_X         (6*8)
  455. #define RGDISP_X        (5*6)
  456. #define RGDISP_Y        (3*8)
  457. #define RGDISP_Y_SEP    8
  458.  
  459. static void show_reg(int regbank )
  460. {
  461.     int i,offset;
  462.     char buffer[256];
  463.     int ypos=RGDISP_Y;
  464.     int xpos=RGDISP_X;
  465.  
  466.     switch (regbank)
  467.     {
  468.         case 1:
  469.             sprintf(buffer,"VRAM Control: %08lx",0x00420000L);
  470.             ui_text(buffer,TITLE_X,ypos);
  471.             ypos+=RGDISP_Y_SEP;
  472.             for( i=0; i<0x10; i+=2 )
  473.             {
  474.                 sprintf(buffer,"%04x",READ_WORD(&namcos2_68k_vram_ctrl[i]));
  475.                 ui_text(buffer,1*RGDISP_X,ypos);
  476.  
  477.                 sprintf(buffer,"%04x",READ_WORD(&namcos2_68k_vram_ctrl[0x10+i]));
  478.                 ui_text(buffer,2*RGDISP_X,ypos);
  479.  
  480.                 sprintf(buffer,"%04x",READ_WORD(&namcos2_68k_vram_ctrl[0x20+i]));
  481.                 ui_text(buffer,3*RGDISP_X,ypos);
  482.  
  483.                 sprintf(buffer,"%04x",READ_WORD(&namcos2_68k_vram_ctrl[0x30+i]));
  484.                 ui_text(buffer,4*RGDISP_X,ypos);
  485.  
  486.                 ypos+=RGDISP_Y_SEP;
  487.             }
  488.  
  489.             ypos+=RGDISP_Y_SEP;
  490.             ypos+=RGDISP_Y_SEP;
  491.             sprintf(buffer,"Sprite Bank : %08lx",0x00c40000L);
  492.             ui_text(buffer,TITLE_X,ypos);
  493.             ypos+=RGDISP_Y_SEP;
  494.             sprintf(buffer,"%04x",namcos2_68k_sprite_bank_r(0));
  495.             ui_text(buffer,RGDISP_X,ypos);
  496.  
  497.             ypos+=RGDISP_Y_SEP;
  498.             ypos+=RGDISP_Y_SEP;
  499.             sprintf(buffer,"Palette Control: %08lx",0x00443000L);
  500.             ui_text(buffer,TITLE_X,ypos);
  501.             ypos+=RGDISP_Y_SEP;
  502.             for( i=0; i<0x08; i+=2 )
  503.             {
  504.                 sprintf(buffer,"%04x",READ_WORD(&namcos2_68k_palette_ram[0x3000 + i]));
  505.                 ui_text(buffer,1*RGDISP_X,ypos);
  506.                 sprintf(buffer,"%04x",READ_WORD(&namcos2_68k_palette_ram[0x3008 + i]));
  507.                 ui_text(buffer,2*RGDISP_X,ypos);
  508.                 ypos+=RGDISP_Y_SEP;
  509.             }
  510.  
  511.             break;
  512.         case 2:
  513.             ypos+=RGDISP_Y_SEP;
  514.             ypos+=RGDISP_Y_SEP;
  515.             sprintf(buffer,"ROZ Control: %08lx",0x00cc0000L);
  516.             ui_text(buffer,TITLE_X,ypos);
  517.             ypos+=RGDISP_Y_SEP;
  518.             for( i=0; i<0x08; i+=2 )
  519.             {
  520.                 sprintf(buffer,"%04x",READ_WORD(&namcos2_68k_roz_ctrl[i]));
  521.                 ui_text(buffer,1*RGDISP_X,ypos);
  522.                 sprintf(buffer,"%04x",READ_WORD(&namcos2_68k_roz_ctrl[0x08+i]));
  523.                 ui_text(buffer,2*RGDISP_X,ypos);
  524.                 ypos+=RGDISP_Y_SEP;
  525.             }
  526.             ypos+=RGDISP_Y_SEP;
  527.             ypos+=RGDISP_Y_SEP;
  528.             sprintf(buffer,"Sprite Bank : %08lx",0x00c40000L);
  529.             ui_text(buffer,TITLE_X,ypos);
  530.             ypos+=RGDISP_Y_SEP;
  531.             sprintf(buffer,"%04x",namcos2_68k_sprite_bank_r(0));
  532.             ui_text(buffer,RGDISP_X,ypos);
  533.             break;
  534.         case 3:
  535.             sprintf(buffer,"Protection Key: %08lx",0x00d00000L);
  536.             ui_text(buffer,TITLE_X,ypos);
  537.             ypos+=RGDISP_Y_SEP;
  538.             for( i=0; i<0x10; i+=2 )
  539.             {
  540.                 sprintf(buffer,"%04x",READ_WORD(&namcos2_68k_key[i]));
  541.                 ui_text(buffer,RGDISP_X,ypos);
  542.                 ypos+=RGDISP_Y_SEP;
  543.             }
  544.             break;
  545.         case 4:
  546.             sprintf(buffer,"IRQ Control: %08lx",0x001c0000L);
  547.             ui_text(buffer,TITLE_X,ypos);
  548.             ypos+=RGDISP_Y_SEP;
  549.             for( i=0; i<0x20; i++ )
  550.             {
  551.                 sprintf(buffer,"%04x",READ_WORD(&namcos2_68k_master_C148[i]));
  552.                 ui_text(buffer,RGDISP_X,ypos);
  553.  
  554.                 sprintf(buffer,"%04x",READ_WORD(&namcos2_68k_slave_C148[i]));
  555.                 ui_text(buffer,2*RGDISP_X,ypos);
  556.                 ypos+=RGDISP_Y_SEP;
  557.             }
  558.             break;
  559.         case 5:
  560.             sprintf(buffer,"Sprite RAM: %08lx",0x00c00000L);
  561.             ui_text(buffer,TITLE_X,ypos);
  562.             ypos+=RGDISP_Y_SEP;
  563.             sprintf(buffer,"SZ S -Y-  F F B NUM Q  -X-  SZ C P");
  564.             ui_text(buffer,12,ypos);
  565.             ypos+=RGDISP_Y_SEP;
  566.             offset=(namcos2_68k_sprite_bank_r(0)&0x000f)*(128*8);
  567.             for( i=0; i<(0x10*0x08); i+=0x08 )
  568.             {
  569.                 xpos=12;
  570.  
  571.                 sprintf(buffer,"%02x %01x %03x  %01x %01x %01x %03x %01x  %03x  %02x %01x %01x",
  572.                          ((READ_WORD(&namcos2_sprite_ram[offset+i+0x00]))>>0x0a)&0x003f,
  573.                          ((READ_WORD(&namcos2_sprite_ram[offset+i+0x00]))>>0x09)&0x0001,
  574.                          ((READ_WORD(&namcos2_sprite_ram[offset+i+0x00]))>>0x00)&0x01ff,
  575.  
  576.                          ((READ_WORD(&namcos2_sprite_ram[offset+i+0x02]))>>0x0f)&0x0001,
  577.                          ((READ_WORD(&namcos2_sprite_ram[offset+i+0x02]))>>0x0e)&0x0001,
  578.                          ((READ_WORD(&namcos2_sprite_ram[offset+i+0x02]))>>0x0d)&0x0001,
  579.                          ((READ_WORD(&namcos2_sprite_ram[offset+i+0x02]))>>0x02)&0x07ff,
  580.                          ((READ_WORD(&namcos2_sprite_ram[offset+i+0x02]))>>0x00)&0x0003,
  581.  
  582.                          ((READ_WORD(&namcos2_sprite_ram[offset+i+0x04]))>>0x00)&0x03ff,
  583.  
  584.                          ((READ_WORD(&namcos2_sprite_ram[offset+i+0x06]))>>0x0a)&0x003f,
  585.                          ((READ_WORD(&namcos2_sprite_ram[offset+i+0x06]))>>0x04)&0x000f,
  586.                          ((READ_WORD(&namcos2_sprite_ram[offset+i+0x06]))>>0x00)&0x0007);
  587.                 ui_text(buffer,xpos,ypos);
  588.                 ypos+=RGDISP_Y_SEP;
  589.             }
  590.             ypos+=RGDISP_Y_SEP;
  591.             sprintf(buffer,"Sprite Bank : %08lx",0x00c40000L);
  592.             ui_text(buffer,TITLE_X,ypos);
  593.             ypos+=RGDISP_Y_SEP;
  594.             sprintf(buffer,"%04x",namcos2_68k_sprite_bank_r(0));
  595.             ui_text(buffer,RGDISP_X,ypos);
  596.             break;
  597.         default:
  598.             break;
  599.     }
  600. }
  601. #endif
  602.  
  603. INLINE unsigned char fetch_rotated_pixel(int xind, int yind)
  604. {
  605.     unsigned char* gfxdata;
  606.     int ram_offset,pix_x,pix_y,tile;
  607.  
  608.     /* First reduce the x/y to tile & x/y subpixels */
  609.     ram_offset=(((yind>>3)<<8)+(xind>>3))<<1;
  610.     pix_x=xind&0x07;
  611.     pix_y=yind&0x07;
  612.  
  613. #ifndef PREROTATE_GFX
  614.     if(Machine->orientation & ORIENTATION_SWAP_XY) { int tmp=pix_x; pix_x=pix_y; pix_y=tmp; }
  615. #endif
  616.  
  617.     /* Now fetch the tile number from ROZ RAM */
  618.     tile=READ_WORD(&namcos2_68k_roz_ram[ram_offset]);
  619.  
  620.     /* Now extract the pixel from the tile gfx */
  621.     gfxdata=get_gfx_pointer(Machine->gfx[GFX_ROZ],tile,pix_y);
  622.     return gfxdata[pix_x];
  623. }
  624.  
  625.  
  626. static void draw_layerROZ( struct osd_bitmap *dest_bitmap)
  627. {
  628.     const struct GfxElement *rozgfx=Machine->gfx[GFX_ROZ];
  629.     int dest_x,dest_x_delta,dest_x_start,dest_x_end,tmp_x;
  630.     int dest_y,dest_y_delta,dest_y_start,dest_y_end,tmp_y;
  631.     int right_dx,right_dy,down_dx,down_dy,start_x,start_y;
  632.     unsigned short *paldata;
  633.     int colour;
  634.  
  635.     /* These need to be sign extended for arithmetic useage */
  636.     right_dx = namcos2_68k_roz_ctrl_r(0x06);
  637.     right_dy = namcos2_68k_roz_ctrl_r(0x02);
  638.     down_dx  = namcos2_68k_roz_ctrl_r(0x04);
  639.     down_dy  = namcos2_68k_roz_ctrl_r(0x00);
  640.     start_y  = namcos2_68k_roz_ctrl_r(0x0a);
  641.     start_x  = namcos2_68k_roz_ctrl_r(0x08);
  642.  
  643.     /* Sign extend the deltas */
  644.     if(right_dx&0x8000) right_dx|=0xffff0000;
  645.     if(right_dy&0x8000) right_dy|=0xffff0000;
  646.     if(down_dx &0x8000) down_dx |=0xffff0000;
  647.     if(down_dy &0x8000) down_dy |=0xffff0000;
  648.  
  649.     /* Correct to 16 bit fixed point from 8/12 bit */
  650.     right_dx <<=8;
  651.     right_dy <<=8;
  652.     down_dx  <<=8;
  653.     down_dy  <<=8;
  654.     start_x  <<=12;
  655.     start_y  <<=12;
  656.  
  657.     /* Correction factor is needed for the screen offset */
  658.     start_x+=38*right_dx;
  659.     start_y+=38*right_dy;
  660.  
  661.     /* Pre-calculate the colour palette array pointer */
  662.     colour=(namcos2_68k_sprite_bank_r(0)>>8)&0x000f;
  663.     paldata = &rozgfx->colortable[rozgfx->color_granularity * colour];
  664.  
  665.     /* Select correct drawing code based on destination bitmap pixel depth */
  666.  
  667.     if(dest_bitmap->depth == 16)
  668.     {
  669.         unsigned short *dest_line,pixel;
  670.  
  671.         if(Machine->orientation & ORIENTATION_SWAP_XY)
  672.         {
  673.             int tmp;
  674.             tmp=right_dx; right_dx=down_dx; down_dx=tmp;
  675.             tmp=right_dy; right_dy=down_dy; down_dy=tmp;
  676.         }
  677.  
  678.         dest_y_delta=(Machine->orientation & ORIENTATION_FLIP_Y)?-1:1;
  679.         dest_y_start=(Machine->orientation & ORIENTATION_FLIP_Y)?dest_bitmap->height-1:0;
  680.         dest_y_end  =(Machine->orientation & ORIENTATION_FLIP_Y)?-1:dest_bitmap->height;
  681.  
  682.         dest_x_delta=(Machine->orientation & ORIENTATION_FLIP_X)?-1:1;
  683.         dest_x_start=(Machine->orientation & ORIENTATION_FLIP_X)?dest_bitmap->width-1:0;
  684.         dest_x_end  =(Machine->orientation & ORIENTATION_FLIP_X)?-1:dest_bitmap->width;
  685.  
  686.         for( dest_y=dest_y_start; dest_y!=dest_y_end; dest_y+=dest_y_delta )
  687.         {
  688.             dest_line = (unsigned short*)dest_bitmap->line[dest_y];
  689.             tmp_x = start_x;
  690.             tmp_y = start_y;
  691.  
  692.             for( dest_x=dest_x_start; dest_x!=dest_x_end; dest_x+=dest_x_delta )
  693.             {
  694.                 int xind=(tmp_x>>16)&ROTATE_MASK_HEIGHT;
  695.                 int yind=(tmp_y>>16)&ROTATE_MASK_WIDTH;
  696.  
  697.                 pixel= fetch_rotated_pixel(xind,yind);
  698.  
  699.                 /* Only process non-transparent pixels */
  700.                 if(pixel!=0xff)
  701.                 {
  702.                     /* Now remap the colour space of the pixel and store */
  703.                     dest_line[dest_x]=paldata[pixel];
  704.                 }
  705.                 tmp_x += right_dx;
  706.                 tmp_y += right_dy;
  707.             }
  708.             start_x += down_dx;
  709.             start_y += down_dy;
  710.         }
  711.     }
  712.     else
  713.     {
  714.         unsigned char *dest_line,pixel;
  715.  
  716.         if(Machine->orientation & ORIENTATION_SWAP_XY)
  717.         {
  718.             int tmp;
  719.             tmp=right_dx; right_dx=down_dx; down_dx=tmp;
  720.             tmp=right_dy; right_dy=down_dy; down_dy=tmp;
  721.         }
  722.  
  723.         dest_y_delta=(Machine->orientation & ORIENTATION_FLIP_Y)?-1:1;
  724.         dest_y_start=(Machine->orientation & ORIENTATION_FLIP_Y)?dest_bitmap->height-1:0;
  725.         dest_y_end  =(Machine->orientation & ORIENTATION_FLIP_Y)?-1:dest_bitmap->height;
  726.  
  727.         dest_x_delta=(Machine->orientation & ORIENTATION_FLIP_X)?-1:1;
  728.         dest_x_start=(Machine->orientation & ORIENTATION_FLIP_X)?dest_bitmap->width-1:0;
  729.         dest_x_end  =(Machine->orientation & ORIENTATION_FLIP_X)?-1:dest_bitmap->width;
  730.  
  731.         for( dest_y=dest_y_start; dest_y!=dest_y_end; dest_y+=dest_y_delta )
  732.         {
  733.             dest_line = dest_bitmap->line[dest_y];
  734.             tmp_x = start_x;
  735.             tmp_y = start_y;
  736.  
  737.             for( dest_x=dest_x_start; dest_x!=dest_x_end; dest_x+=dest_x_delta )
  738.             {
  739.                 int xind=(tmp_x>>16)&ROTATE_MASK_HEIGHT;
  740.                 int yind=(tmp_y>>16)&ROTATE_MASK_WIDTH;
  741.  
  742.                 pixel= fetch_rotated_pixel(xind,yind);
  743.  
  744.                 /* Only process non-transparent pixels */
  745.                 if(pixel!=0xff)
  746.                 {
  747.                     /* Now remap the colour space of the pixel and store */
  748.                     dest_line[dest_x]=paldata[pixel];
  749.                 }
  750.                 tmp_x += right_dx;
  751.                 tmp_y += right_dy;
  752.             }
  753.             start_x += down_dx;
  754.             start_y += down_dy;
  755.         }
  756.     }
  757. }
  758.  
  759.  
  760. static void draw_sprites_default( struct osd_bitmap *bitmap, int priority )
  761. {
  762.     int sprn,flipy,flipx,ypos,xpos,sizex,sizey,scalex,scaley;
  763.     int offset,offset0,offset2,offset4,offset6;
  764.     int loop,spr_region;
  765.     struct rectangle rect;
  766.  
  767.     offset=(namcos2_68k_sprite_bank_r(0)&0x000f)*(128*8);
  768.  
  769.     for(loop=0;loop < 128;loop++)
  770.     {
  771.         /****************************************
  772.         * Sprite data is 8 byte packed format   *
  773.         *                                       *
  774.         * Offset 0,1                            *
  775.         *   Sprite Y position           D00-D08 *
  776.         *   Sprite Size 16/32           D09     *
  777.         *   Sprite Size Y               D10-D15 *
  778.         *                                       *
  779.         * Offset 2,3                            *
  780.         *   Sprite Quadrant             D00-D01 *
  781.         *   Sprite Number               D02-D12 *
  782.         *   Sprite ROM Bank select      D13     *
  783.         *   Sprite flip X               D14     *
  784.         *   Sprite flip Y               D15     *
  785.         *                                       *
  786.         * Offset 4,5                            *
  787.         *   Sprite X position           D00-D10 *
  788.         *                                       *
  789.         * Offset 6,7                            *
  790.         *   Sprite priority             D00-D02 *
  791.         *   Sprite colour index         D04-D07 *
  792.         *   Sprite Size X               D10-D15 *
  793.         *                                       *
  794.         ****************************************/
  795.  
  796.         offset0 = READ_WORD(&namcos2_sprite_ram[offset+(loop*8)+0]);
  797.         offset2 = READ_WORD(&namcos2_sprite_ram[offset+(loop*8)+2]);
  798.         offset4 = READ_WORD(&namcos2_sprite_ram[offset+(loop*8)+4]);
  799.         offset6 = READ_WORD(&namcos2_sprite_ram[offset+(loop*8)+6]);
  800.  
  801.         /* Fetch sprite size registers */
  802.  
  803.         sizey=((offset0>>10)&0x3f)+1;
  804.         sizex=(offset6>>10)&0x3f;
  805.  
  806.         if((offset0&0x0200)==0) sizex>>=1;
  807.  
  808.         if((sizey-1) && sizex && (offset6&0x0007)==priority)
  809.         {
  810.             rect=Machine->drv->visible_area;
  811.  
  812.             sprn=(offset2>>2)&0x7ff;
  813.             spr_region=(offset2&0x2000)?GFX_OBJ2:GFX_OBJ1;
  814.  
  815.             ypos=(0x1ff-(offset0&0x01ff))-0x50+0x02;
  816.             xpos=(offset4&0x03ff)-0x50+0x07;
  817.  
  818.             flipy=offset2&0x8000;
  819.             flipx=offset2&0x4000;
  820.  
  821.             scalex=((sizex<<16)/((offset0&0x0200)?0x20:0x10));
  822.             scaley=((sizey<<16)/((offset0&0x0200)?0x20:0x10));
  823.  
  824.             /* Set the clipping rect to mask off the other portion of the sprite */
  825.             rect.min_x=xpos;
  826.             rect.max_x=xpos+(sizex-1);
  827.             rect.min_y=ypos;
  828.             rect.max_y=ypos+(sizey-1);
  829.  
  830.             if((offset0&0x0200)==0)
  831.             {
  832.                 if(((offset2&0x0001) && !flipx) || (!(offset2&0x0001) && flipx)) xpos-=sizex;
  833.                 if(((offset2&0x0002) && !flipy) || (!(offset2&0x0002) && flipy)) ypos-=sizey;
  834.             }
  835.  
  836.             if((scalex==(1<<16)) && (scaley==(1<<16)))
  837.             {
  838.                 drawgfx(bitmap,Machine->gfx[spr_region],
  839.                     sprn,
  840.                     (offset6>>4)&0x000f,     /* Selected colour bank */
  841.                     flipx,flipy,
  842.                     xpos,ypos,
  843.                     &rect,TRANSPARENCY_PEN,0xff);
  844.             }
  845.             else if(scalex && scaley)
  846.             {
  847.                 drawgfxzoom(bitmap,Machine->gfx[spr_region],
  848.                     sprn,
  849.                     (offset6>>4)&0x000f,     /* Selected colour bank */
  850.                     flipx,flipy,
  851.                     xpos,ypos,
  852.                     &rect,TRANSPARENCY_PEN,0xff,
  853.                     scalex,scaley);
  854.             }
  855.         }
  856.     }
  857. }
  858.  
  859.  
  860. static void draw_sprites_finallap( struct osd_bitmap *bitmap, int priority )
  861. {
  862.     int sprn,flipy,flipx,ypos,xpos,sizex,sizey,scalex,scaley;
  863.     int offset,offset0,offset2,offset4,offset6;
  864.     int loop,spr_region;
  865.     struct rectangle rect;
  866.  
  867.     offset=(namcos2_68k_sprite_bank_r(0)&0x000f)*(128*8);
  868.  
  869.     for(loop=0;loop < 128;loop++)
  870.     {
  871.         /****************************************
  872.         * Sprite data is 8 byte packed format   *
  873.         *                                       *
  874.         * Offset 0,1                            *
  875.         *   Sprite Y position           D00-D08 *
  876.         *   Sprite ROM Bank select      D09     * DIFFERENT FROM DEFAULT SPRITES
  877.         *   Sprite Size Y               D10-D15 *
  878.         *                                       *
  879.         * Offset 2,3                            *
  880.         *   Sprite Quadrant             D00-D01 *
  881.         *   Sprite Number               D02-D12 *
  882.         *   Sprite Size 16/32           D13     * DIFFERENT FROM DEFAULT SPRITES
  883.         *   Sprite flip X               D14     *
  884.         *   Sprite flip Y               D15     *
  885.         *                                       *
  886.         * Offset 4,5                            *
  887.         *   Sprite X position           D00-D10 *
  888.         *                                       *
  889.         * Offset 6,7                            *
  890.         *   Sprite priority             D00-D03 * DIFFERENT FROM DEFAULT SPRITES 4 BIT
  891.         *   Sprite colour index         D04-D07 *
  892.         *   Sprite Size X               D10-D15 *
  893.         *                                       *
  894.         ****************************************/
  895.  
  896.         offset0 = READ_WORD(&namcos2_sprite_ram[offset+(loop*8)+0]);
  897.         offset2 = READ_WORD(&namcos2_sprite_ram[offset+(loop*8)+2]);
  898.         offset4 = READ_WORD(&namcos2_sprite_ram[offset+(loop*8)+4]);
  899.         offset6 = READ_WORD(&namcos2_sprite_ram[offset+(loop*8)+6]);
  900.  
  901.         /* Fetch sprite size registers */
  902.  
  903.         sizey=((offset0>>10)&0x3f)+1;
  904.         sizex=(offset6>>10)&0x3f;
  905.  
  906.         if((offset2&0x2000)==0) sizex>>=1;
  907.  
  908.         if((sizey-1) && sizex && (offset6&0x000f)==priority)
  909.         {
  910.             rect=Machine->drv->visible_area;
  911.  
  912.             sprn=(offset2>>2)&0x7ff;
  913.             spr_region=(offset0&0x0200)?GFX_OBJ2:GFX_OBJ1;
  914.             spr_region=GFX_OBJ1;    // Always fixed on Final Lap
  915.  
  916.             if(offset0&0x0200)
  917.             {
  918.                 ypos=((offset0&0x0100)?-0x100:0)+(offset0&0x00ff)+0xa8;    // 0x70
  919.                 xpos=((offset4&0x0200)?-0x200:0)+(offset4&0x01ff)+0x90;    // 0x90
  920.             }
  921.             else
  922.             {
  923.                 ypos=(0x1ff-(offset0&0x01ff))-0x50+0x02;
  924.                 xpos=(offset4&0x03ff)-0x50+0x07;
  925.             }
  926.  
  927.  
  928.             flipy=offset2&0x8000;
  929.             flipx=offset2&0x4000;
  930.  
  931.             scalex=((sizex<<16)/((offset2&0x2000)?0x20:0x10));
  932.             scaley=((sizey<<16)/((offset2&0x2000)?0x20:0x10));
  933.  
  934.             /* Set the clipping rect to mask off the other portion of the sprite */
  935.             rect.min_x=xpos;
  936.             rect.max_x=xpos+(sizex-1);
  937.             rect.min_y=ypos;
  938.             rect.max_y=ypos+(sizey-1);
  939.  
  940.             if((offset2&0x2000)==0)
  941.             {
  942.                 if(((offset2&0x0001) && !flipx) || (!(offset2&0x0001) && flipx)) xpos-=sizex;
  943.                 if(((offset2&0x0002) && !flipy) || (!(offset2&0x0002) && flipy)) ypos-=sizey;
  944.             }
  945.  
  946.             if((scalex==(1<<16)) && (scaley==(1<<16)))
  947.             {
  948.                 drawgfx(bitmap,Machine->gfx[spr_region],
  949.                     sprn,
  950.                     (offset6>>4)&0x000f,     /* Selected colour bank */
  951.                     flipx,flipy,
  952.                     xpos,ypos,
  953.                     &rect,TRANSPARENCY_PEN,0xff);
  954.             }
  955.             else if(scalex && scaley)
  956.             {
  957.                 drawgfxzoom(bitmap,Machine->gfx[spr_region],
  958.                     sprn,
  959.                     (offset6>>4)&0x000f,     /* Selected colour bank */
  960.                     flipx,flipy,
  961.                     xpos,ypos,
  962.                     &rect,TRANSPARENCY_PEN,0xff,
  963.                     scalex,scaley);
  964.             }
  965.         }
  966.     }
  967. }
  968.  
  969. void namcos2_vh_update_default(struct osd_bitmap *bitmap, int full_refresh)
  970. {
  971.     int priority;
  972.     static int show[10] = {1,1,1,1,1,1,1,1,1,1};
  973.  
  974.     tilemap_update(namcos2_tilemap0);
  975.     tilemap_update(namcos2_tilemap1);
  976.     tilemap_update(namcos2_tilemap2);
  977.     tilemap_update(namcos2_tilemap3);
  978.     tilemap_update(namcos2_tilemap4);
  979.     tilemap_update(namcos2_tilemap5);
  980.  
  981.     /* Only piss around with the palette if we are in 8 bit mode as 16 bit */
  982.     /* mode has a direct mapping and doesnt need palette management        */
  983.     {
  984.         /* Initialise palette_used_colors array */
  985.         palette_init_used_colors();
  986.  
  987.         /* Mark any colours in the palette_used_colors array */
  988.         /* Only process ROZ if she is enabled */
  989.         if(((namcos2_68k_sprite_bank_r(0)>>12)&0x07)>0) namcos2_mark_used_ROZ_colours();
  990.         /* Finally the sprites */
  991.         namcos2_mark_used_sprite_colours();
  992.  
  993.         if (palette_recalc())
  994.         {
  995.             /* Mark all planes as dirty */
  996.             tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  997.         }
  998.         tilemap_render(ALL_TILEMAPS);
  999.     }
  1000.  
  1001.  
  1002.     /* Scrub the bitmap clean */
  1003.     fillbitmap(bitmap,Machine->pens[0],&Machine->drv->visible_area);
  1004.  
  1005.     /* Render the screen */
  1006.     for(priority=0;priority<=7;priority++)
  1007.     {
  1008.         if((namcos2_68k_vram_ctrl_r(0x20)&0x07)==priority && show[0]) tilemap_draw(bitmap,namcos2_tilemap0,0);
  1009.         if((namcos2_68k_vram_ctrl_r(0x22)&0x07)==priority && show[1]) tilemap_draw(bitmap,namcos2_tilemap1,0);
  1010.         if((namcos2_68k_vram_ctrl_r(0x24)&0x07)==priority && show[2]) tilemap_draw(bitmap,namcos2_tilemap2,0);
  1011.         if((namcos2_68k_vram_ctrl_r(0x26)&0x07)==priority && show[3]) tilemap_draw(bitmap,namcos2_tilemap3,0);
  1012.         if((namcos2_68k_vram_ctrl_r(0x28)&0x07)==priority && show[4]) tilemap_draw(bitmap,namcos2_tilemap4,0);
  1013.         if((namcos2_68k_vram_ctrl_r(0x2a)&0x07)==priority && show[5]) tilemap_draw(bitmap,namcos2_tilemap5,0);
  1014.  
  1015.         /* Draw ROZ if enabled */
  1016.         if(priority>=1 && ((namcos2_68k_sprite_bank_r(0)>>12)&0x07)==priority && show[6]) draw_layerROZ(bitmap);
  1017.  
  1018.         /* Sprites */
  1019.         draw_sprites_default( bitmap,priority );
  1020.     }
  1021.  
  1022. #ifdef NAMCOS2_DEBUG_MODE
  1023.     /* NAMCOS2 Video debugging */
  1024.     if(keyboard_pressed(KEYCODE_Z))     { while( keyboard_pressed(KEYCODE_Z));     show[0]=(show[0])?0:1;  }
  1025.     if(keyboard_pressed(KEYCODE_X))     { while( keyboard_pressed(KEYCODE_X));     show[1]=(show[1])?0:1;  }
  1026.     if(keyboard_pressed(KEYCODE_C))     { while( keyboard_pressed(KEYCODE_C));     show[2]=(show[2])?0:1;  }
  1027.     if(keyboard_pressed(KEYCODE_V))     { while( keyboard_pressed(KEYCODE_V));     show[3]=(show[3])?0:1;  }
  1028.     if(keyboard_pressed(KEYCODE_B))     { while( keyboard_pressed(KEYCODE_B));     show[4]=(show[4])?0:1;  }
  1029.     if(keyboard_pressed(KEYCODE_N))     { while( keyboard_pressed(KEYCODE_N));     show[5]=(show[5])?0:1;  }
  1030.     if(keyboard_pressed(KEYCODE_COMMA)) { while( keyboard_pressed(KEYCODE_COMMA)); show[6]=(show[6])?0:1;  }
  1031.  
  1032.     if(!show[0] || !show[1] || !show[2] || !show[3] || !show[4] || !show[5] || !show[6])
  1033.     {
  1034.         char buffer[256];
  1035.         sprintf(buffer,"Planes %d%d%d%d %d%d %d",show[0],show[1],show[2],show[3],show[4],show[5],show[6]);
  1036.         ui_text(buffer,4,4);
  1037.     }
  1038.  
  1039.     if(0)
  1040.     {
  1041.         char buffer[256];
  1042.         int loop;
  1043.         namcos2_used_colour_count=0;
  1044.         namcos2_used_colour_cached=0;
  1045.         for(loop=0;loop<8192;loop++) if(palette_used_colors[loop]&PALETTE_COLOR_VISIBLE) namcos2_used_colour_count++;
  1046.         for(loop=0;loop<8192;loop++) if(palette_used_colors[loop]&PALETTE_COLOR_CACHED) namcos2_used_colour_cached++;
  1047.         if(namcos2_used_colour_count>namcos2_max_used_colour_count) namcos2_max_used_colour_count=namcos2_used_colour_count;
  1048.         if(namcos2_used_colour_cached>namcos2_max_used_colour_cached) namcos2_max_used_colour_cached=namcos2_used_colour_cached;
  1049.  
  1050.         sprintf(buffer,"Pens   = %03d (%03d)",namcos2_used_colour_count,namcos2_max_used_colour_count);
  1051.         ui_text(buffer,4,12);
  1052.         sprintf(buffer,"Cached = %03d (%03d)",namcos2_used_colour_cached,namcos2_max_used_colour_cached);
  1053.         ui_text(buffer,4,20);
  1054.         /* sprintf(buffer,"RunOut = %03d (%03d)",palette_ran_out,palette_max_ran_out); */
  1055.         /* ui_text(buffer,4,28); */
  1056.         sprintf(buffer,"Depth  = %d",Machine->scrbitmap->depth);
  1057.         ui_text(buffer,4,36);
  1058.     }
  1059.  
  1060.     {
  1061.         static int regshow = 0;
  1062.         if(keyboard_pressed(KEYCODE_L)) { while( keyboard_pressed(KEYCODE_L)); regshow++;if(regshow>5) regshow=0; }
  1063.         if(regshow) show_reg(regshow);
  1064.     }
  1065. #endif
  1066. }
  1067.  
  1068.  
  1069. void namcos2_vh_update_finallap(struct osd_bitmap *bitmap, int full_refresh)
  1070. {
  1071.     int priority;
  1072.     static int show[10] = {1,1,1,1,1,1,1,1,1,1};
  1073.  
  1074.     tilemap_update(namcos2_tilemap0);
  1075.     tilemap_update(namcos2_tilemap1);
  1076.     tilemap_update(namcos2_tilemap2);
  1077.     tilemap_update(namcos2_tilemap3);
  1078.     tilemap_update(namcos2_tilemap4);
  1079.     tilemap_update(namcos2_tilemap5);
  1080.  
  1081.     /* Only piss around with the palette if we are in 8 bit mode as 16 bit */
  1082.     /* mode has a direct mapping and doesnt need palette management        */
  1083.     {
  1084.         /* Initialise palette_used_colors array */
  1085.         palette_init_used_colors();
  1086.  
  1087.         /* Mark any colours in the palette_used_colors array */
  1088.         namcos2_mark_used_sprite_colours();
  1089.  
  1090.         if (palette_recalc())
  1091.         {
  1092.             /* Mark all planes as dirty */
  1093.             tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  1094.         }
  1095.         tilemap_render(ALL_TILEMAPS);
  1096.     }
  1097.  
  1098.  
  1099.     /* Scrub the bitmap clean */
  1100.     fillbitmap(bitmap,Machine->pens[0],&Machine->drv->visible_area);
  1101.  
  1102.     /* Render the screen */
  1103.     for(priority=0;priority<=15;priority++)
  1104.     {
  1105.         if((namcos2_68k_vram_ctrl_r(0x20)&0x0f)==priority && show[0]) tilemap_draw(bitmap,namcos2_tilemap0,0);
  1106.         if((namcos2_68k_vram_ctrl_r(0x22)&0x0f)==priority && show[1]) tilemap_draw(bitmap,namcos2_tilemap1,0);
  1107.         if((namcos2_68k_vram_ctrl_r(0x24)&0x0f)==priority && show[2]) tilemap_draw(bitmap,namcos2_tilemap2,0);
  1108.         if((namcos2_68k_vram_ctrl_r(0x26)&0x0f)==priority && show[3]) tilemap_draw(bitmap,namcos2_tilemap3,0);
  1109.         if((namcos2_68k_vram_ctrl_r(0x28)&0x0f)==priority && show[4]) tilemap_draw(bitmap,namcos2_tilemap4,0);
  1110.         if((namcos2_68k_vram_ctrl_r(0x2a)&0x0f)==priority && show[5]) tilemap_draw(bitmap,namcos2_tilemap5,0);
  1111.         /* Not sure if priority should be 0x07 or 0x0f */
  1112.  
  1113.         /* Sprites */
  1114.         draw_sprites_finallap( bitmap,priority );
  1115.     }
  1116.  
  1117.  
  1118.     /********************************************************************/
  1119.     /*                                                                  */
  1120.     /* Final Lap roadway implementation notes                           */
  1121.     /*                                                                  */
  1122.     /* namcos2_68k_roadtile_ram                                         */
  1123.     /* ------------------------                                         */
  1124.     /* Overall tilemap looks to be 64 wide x 512 deep in terms of tiles */
  1125.     /* this gives and overall dimension of 512 x 4096 pixels. This is   */
  1126.     /* very large and it may be that it uses double buffering which     */
  1127.     /* would halve the depth of the buffer.                             */
  1128.     /*                                                                  */
  1129.     /* Each row of the tilemap is made of 64 words (128 bytes), the     */
  1130.     /* first byte most likely holds the colour+attr, the second byte    */
  1131.     /* contains the tilenumber, this references a RAM based tile        */
  1132.     /* definition within namcos2_68k_roadgfx_ram, tiles are 8x8 8bpp.   */
  1133.     /*                                                                  */
  1134.     /* namcos2_68k_roadgfx_ram                                          */
  1135.     /* -----------------------                                          */
  1136.     /* This ram holds the gfx data for the 8x8 tiles in 8bpp format.    */
  1137.     /* The data is arranged in 2 x 32 byte blocks with each block       */
  1138.     /* arranged in a 4 x 8 byte pattern.                                */
  1139.     /*                                                                  */
  1140.     /* Bxxby == Byte <xx> bit <y>                                       */
  1141.     /*                                                                  */
  1142.     /* So Pixel 0,0 = B00b0 B01b0 B02b0 B03b0 B32b0 B33b0 B34b0 B35b0   */
  1143.     /*    Pixel 0,1 = B00b1 B01b1 B02b1 B03b1 B32b1 B33b1 B34b1 B35b1   */
  1144.     /*                          ..................                      */
  1145.     /*    Pixel 0,7 = B00b7 B01b7 B02b7 B03b7 B32b7 B33b7 B34b7 B35b7   */
  1146.     /*                                                                  */
  1147.     /*    Pixel 1,0 = B04b0 B05b0 B06b0 B07b0 B36b0 B37b0 B38b0 B39b0   */
  1148.     /*                                                                  */
  1149.     /********************************************************************/
  1150.  
  1151.     /* Flat rendering of the road tilemap */
  1152.     if(0)
  1153.     {
  1154.         int loop,linel,data;
  1155.         unsigned char *dest_line;
  1156.         for(loop=0;loop<28*8;loop++)
  1157.         {
  1158.             dest_line = bitmap->line[loop];
  1159.             for(linel=0;linel<128;linel+=2)
  1160.             {
  1161.                 data=READ_WORD(&namcos2_68k_roadtile_ram[(loop*128)+linel]);
  1162.                 *(dest_line++)=(data&0x000f)>>0;
  1163.                 *(dest_line++)=(data&0x00f0)>>4;
  1164.                 *(dest_line++)=(data&0x0f00)>>8;
  1165.                 *(dest_line++)=(data&0xf000)>>12;
  1166.             }
  1167.         }
  1168.     }
  1169.  
  1170. #ifdef NAMCOS2_DEBUG_MODE
  1171.     /* NAMCOS2 Video debugging */
  1172.     if(keyboard_pressed(KEYCODE_Z))     { while( keyboard_pressed(KEYCODE_Z));     show[0]=(show[0])?0:1;  }
  1173.     if(keyboard_pressed(KEYCODE_X))     { while( keyboard_pressed(KEYCODE_X));     show[1]=(show[1])?0:1;  }
  1174.     if(keyboard_pressed(KEYCODE_C))     { while( keyboard_pressed(KEYCODE_C));     show[2]=(show[2])?0:1;  }
  1175.     if(keyboard_pressed(KEYCODE_V))     { while( keyboard_pressed(KEYCODE_V));     show[3]=(show[3])?0:1;  }
  1176.     if(keyboard_pressed(KEYCODE_B))     { while( keyboard_pressed(KEYCODE_B));     show[4]=(show[4])?0:1;  }
  1177.     if(keyboard_pressed(KEYCODE_N))     { while( keyboard_pressed(KEYCODE_N));     show[5]=(show[5])?0:1;  }
  1178.  
  1179.     if(!show[0] || !show[1] || !show[2] || !show[3] || !show[4] || !show[5])
  1180.     {
  1181.         char buffer[256];
  1182.         sprintf(buffer,"Planes %d%d%d%d %d%d",show[0],show[1],show[2],show[3],show[4],show[5]);
  1183.         ui_text(buffer,4,4);
  1184.     }
  1185.  
  1186.     {
  1187.         static int regshow = 0;
  1188.         if(keyboard_pressed(KEYCODE_L)) { while( keyboard_pressed(KEYCODE_L)); regshow++;if(regshow>5) regshow=0; }
  1189.         if(regshow) show_reg(regshow);
  1190.     }
  1191.  
  1192.     {
  1193.         if(keyboard_pressed(KEYCODE_S))
  1194.         {
  1195.             FILE *f=NULL;
  1196.             int i;
  1197.  
  1198.             while( keyboard_pressed(KEYCODE_S));
  1199.             f = fopen ("finallap.log", "w");
  1200.             fprintf (f, "Sprite Memory (Bank 0)\n");
  1201.             for (i = 0; i < 0x80; i++)
  1202.                 fprintf (f, "%04x %04x %04x %04x\n",
  1203.                     READ_WORD(&namcos2_sprite_ram[(i*8)+0]),
  1204.                     READ_WORD(&namcos2_sprite_ram[(i*8)+2]),
  1205.                     READ_WORD(&namcos2_sprite_ram[(i*8)+4]),
  1206.                     READ_WORD(&namcos2_sprite_ram[(i*8)+6]));
  1207.             fprintf (f, "\n\n\n\n");
  1208.  
  1209.             fprintf (f, "Sprite Memory (Bank 1)\n");
  1210.             for (i = 0; i < 0x80; i++)
  1211.                 fprintf (f, "%04x %04x %04x %04x\n",
  1212.                     READ_WORD(&namcos2_sprite_ram[0x400+(i*8)+0]),
  1213.                     READ_WORD(&namcos2_sprite_ram[0x400+(i*8)+2]),
  1214.                     READ_WORD(&namcos2_sprite_ram[0x400+(i*8)+4]),
  1215.                     READ_WORD(&namcos2_sprite_ram[0x400+(i*8)+6]));
  1216.             fprintf (f, "\n\n\n\n");
  1217.  
  1218.             fprintf (f, "Road Tile Memory\n");
  1219.             for (i = 0; i < 0x800; i++)
  1220.             {
  1221.                 if((i%4)==0) fprintf(f,"0x%03x    ",i/4);
  1222.                 fprintf (f, "%04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x %04x ",
  1223.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x00]),
  1224.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x02]),
  1225.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x04]),
  1226.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x06]),
  1227.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x08]),
  1228.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x0a]),
  1229.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x0c]),
  1230.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x0e]),
  1231.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x10]),
  1232.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x12]),
  1233.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x14]),
  1234.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x16]),
  1235.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x18]),
  1236.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x1a]),
  1237.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x1c]),
  1238.                     READ_WORD(&namcos2_68k_roadtile_ram[(i*32)+0x1e]));
  1239.                 if((i%4)==3) fprintf(f,"\n");
  1240.             }
  1241.             fprintf (f, "\n\n\n\n");
  1242.  
  1243.             fclose(f);
  1244.         }
  1245.     }
  1246. #endif
  1247. }
  1248.